package com.training1.api.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.training1.core.common.global.Global;
import com.training1.core.common.utils.DateUtils;
import com.training1.core.common.utils.security.MD5;
import com.training1.core.dto.APIResultDto;
import com.training1.core.dto.HelpDto;
import com.training1.core.dto.MemberDto;
import com.training1.core.entity.HelpEntity;
import com.training1.core.entity.MemberEntity;
import com.training1.core.entity.SystemParamEntity;
import com.training1.core.modules.dao.SystemSettingsDao;
import com.training1.core.modules.service.HelpService;
import com.training1.core.modules.service.MemberService;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;

@Api(value = "/api/memberCenter", description = "个人中心首页")
// Swagger annotation
@RestController
@RequestMapping("/api/memberCenter")
public class APIMemberCenterController {
	private static final Logger logger = LoggerFactory
			.getLogger(APIMemberCenterController.class);

	@Resource
	private MemberService memberService;

	@ApiOperation(value = "获取会员账户信息, 参数是手机号")
	@RequestMapping(value = "/getMemberAccountInfo", method = RequestMethod.GET)
	public APIResultDto<Object> getHelpList(@RequestParam String cellPhone) {
		logger.info("获取会员账户信息, cellPhone : " + cellPhone);
		APIResultDto<Object> dto = new APIResultDto<Object>();

		MemberEntity member = memberService.findMemberByPhone(cellPhone);
		if(member != null){
			Map<String, Object> param = new HashMap<String, Object>();//封装数据
			
			MemberDto md = new MemberDto();
			md.setTotalIncome(member.getTotalIncome());
			md.setAvaibleCash(member.getAvaibleCash());
			md.setCusumeCash(member.getCusumeCash());
			md.setInvestmentCash(member.getInvestmentCash());
			//如果没有银行卡号  就是没绑定
			System.out.println(member.getBankCardId());
			if(null == member.getBankCardId() || member.getBankCardId().length() <= 0){
				
				md.setBindStatus("未绑定");
			}else{
				md.setBindStatus("已绑定");
			}
			MemberEntity m = memberService.findCardCount(cellPhone);
			md.setNodeCount(m.getNodeCount());
			
			param.put("accountInfo", md);
			
			dto.setData(param);
			dto.setStatus(APIResultDto.SUCCESS_OK);
			dto.setErrorCode("1");
			dto.setMessage("查询成功");
			return dto;
		}else{
			dto.setStatus(APIResultDto.ERROR);
			dto.setErrorCode("1");
			dto.setMessage("账号不存在或已被锁定,请联系平台管理员");
			return dto;
		}
	}


}